{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  \n",
    "+ 学号"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "吴雨婷\n",
    "0165211"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "    晴天 - 周杰伦\n",
      "\n",
      "    故事的小黄花 从出生那年就飘着\n",
      "    童年的荡秋千 随记忆一直晃到现在\n",
      "    rui sou sou xi dou xi la\n",
      "    sou la xi xi xi xi la xi la sou\n",
      "    吹着前奏望着天空 我想起花瓣试着掉落\n",
      "    \n",
      "\n",
      "    为你翘课的那一天 花落的那一天\n",
      "    教室的那一间 我怎么看不见\n",
      "    消失的下雨天 我好想再淋一遍\n",
      "    没想到失去的勇气我还留着\n",
      "    好想再问一遍 你会等待还是离开\n",
      "    刮风这天我试过握着你手\n",
      "    但偏偏雨渐渐大到我看你不见\n",
      "    还要多久我才能在你身边\n",
      "    等到放晴的那天也许我会比较好一点\n",
      "    从前从前有个人爱你很久\n",
      "    但偏偏风渐渐把距离吹得好远\n",
      "    好不容易又能再多爱一天\n",
      "    但故事的最后你好像还是说了拜拜\n",
      "    \n",
      "\n",
      "    为你翘课的那一天 花落的那一天\n",
      "    教室的那一间 我怎么看不见\n",
      "    消失的下雨天 我好想再淋一遍\n",
      "    没想到失去的勇气我还留着\n",
      "    好想再问一遍 你会等待还是离开\n",
      "    刮风这天我试过握着你手\n",
      "    但偏偏雨渐渐大到我看你不见\n",
      "    还要多久我才能在你身边\n",
      "    等到放晴的那天也许我会比较好一点\n",
      "    从前从前有个人爱你很久\n",
      "    但偏偏风渐渐把距离吹得好远\n",
      "    好不容易又能再多爱一天\n",
      "    但故事的最后你好像还是说了拜拜\n",
      "    \n"
     ]
    }
   ],
   "source": [
    "print(\n",
    "    '''\n",
    "    晴天 - 周杰伦\n",
    "\n",
    "    故事的小黄花 从出生那年就飘着\n",
    "    童年的荡秋千 随记忆一直晃到现在\n",
    "    rui sou sou xi dou xi la\n",
    "    sou la xi xi xi xi la xi la sou\n",
    "    吹着前奏望着天空 我想起花瓣试着掉落\n",
    "    '''\n",
    "    )\n",
    "def chorus():\n",
    "    print(\n",
    "    '''\n",
    "    为你翘课的那一天 花落的那一天\n",
    "    教室的那一间 我怎么看不见\n",
    "    消失的下雨天 我好想再淋一遍\n",
    "    没想到失去的勇气我还留着\n",
    "    好想再问一遍 你会等待还是离开\n",
    "    刮风这天我试过握着你手\n",
    "    但偏偏雨渐渐大到我看你不见\n",
    "    还要多久我才能在你身边\n",
    "    等到放晴的那天也许我会比较好一点\n",
    "    从前从前有个人爱你很久\n",
    "    但偏偏风渐渐把距离吹得好远\n",
    "    好不容易又能再多爱一天\n",
    "    但故事的最后你好像还是说了拜拜\n",
    "    '''\n",
    "    )\n",
    "chorus()\n",
    "chorus()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mean=5.08\n",
      "variance=3.74\n",
      "n=12\n",
      "mean=25.67\n",
      "variance=28.72\n",
      "n=12\n"
     ]
    }
   ],
   "source": [
    "def statistic(*args):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for value in args:\n",
    "        a=a+value            \n",
    "        n+=1\n",
    "    print('mean=%.2f'%(a/n))\n",
    "    for value in args:\n",
    "        b=b+(value-a/n)**2  ##离差平方和\n",
    "    print('variance=%.2f'%(b/n))  ##方差\n",
    "    print('n=%d'%n)\n",
    "\n",
    "statistic(5,6,7,5,5,6,2,6,5,2,3,9)\n",
    "statistic(26,35,24,26,21,20,19,36,25,23,22,31)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "choose  variance,plese input 1\n",
      "choose standard deviation,please input 2\n",
      "1\n",
      "\n",
      "\n",
      "mean=5.08\n",
      "variance=3.74\n",
      "n=12\n",
      "\n",
      "choose  variance,plese input 1\n",
      "choose standard deviation,please input 2\n",
      "2\n",
      "\n",
      "\n",
      "mean=26.79\n",
      "standard deviation=5.67\n",
      "n=14\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "def statistic(*args):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for value in args:\n",
    "        a=a+value\n",
    "        n+=1\n",
    "    for value in args:\n",
    "        b=b+(value-a/n)**2   ##离差平方和\n",
    "    print('choose  variance,plese input 1')  ##通过输入1、2来选择输出方差还是标准差\n",
    "    print('choose standard deviation,please input 2')\n",
    "    c=int(input())\n",
    "    print('\\n\\nmean=%.2f'%(a/n))\n",
    "    if c==1:\n",
    "        print('variance=%.2f'%(b/n))       ##方差\n",
    "    else:\n",
    "        print('standard deviation=%.2f'%math.sqrt(b/n))    ##标准差\n",
    "    print('n=%d\\n'%n)\n",
    "\n",
    "statistic(5,6,7,5,5,6,2,6,5,2,3,9)\n",
    "statistic(26,35,24,26,21,20,19,36,25,23,22,31,33,34)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "choose  variance,plese input 1\n",
      "choose standard deviation,please input 2\n",
      "1\n",
      "if you want to input Standard error、max and min,you can choose 1\n",
      "1\n",
      "\n",
      "\n",
      "mean=5.08\n",
      "variance=3.74\n",
      "standard error=0.16\n",
      "max=9\n",
      "min=2\n",
      "n=12\n",
      "\n",
      "choose  variance,plese input 1\n",
      "choose standard deviation,please input 2\n",
      "2\n",
      "if you want to input Standard error、max and min,you can choose 1\n",
      "2\n",
      "\n",
      "\n",
      "mean=26.79\n",
      "standard deviation=5.67\n",
      "n=14\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "def statistic(*args):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for value in args:\n",
    "        a=a+value\n",
    "        n+=1\n",
    "    for value in args:\n",
    "        b=b+(value-a/n)**2  ##离差平方和\n",
    "    print('choose  variance,plese input 1')    ##通过输入1、2来选择输出方差还是标准差\n",
    "    print('choose standard deviation,please input 2')\n",
    "    c=int(input())\n",
    "    print('if you want to input Standard error、max and min,you can choose 1')  ##通过是否输入1来选择输出标准误最大值最小值\n",
    "    d=int(input())\n",
    "    print('\\n\\nmean=%.2f'%(a/n))\n",
    "    if c==1:\n",
    "        print('variance=%.2f'%(b/n))    ##方差\n",
    "    else:\n",
    "        print('standard deviation=%.2f'%math.sqrt(b/n))   ##标准差\n",
    "    if d==1:\n",
    "        print('standard error=%.2f'%math.sqrt(b/(n**3)))   ##标准误\n",
    "        print('max=%d'%max(args))         ##最大值\n",
    "        print('min=%d'%min(args))         ##最小值\n",
    "    print('n=%d\\n'%n)\n",
    "\n",
    "statistic(5,6,7,5,5,6,2,6,5,2,3,9)\n",
    "statistic(26,35,24,26,21,20,19,36,25,23,22,31,33,34)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
